import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by Administrator on 2014/3/25.
 * Time: 17:29
 */
public class demo2_jsoup {
    static Map<String, String> cookiemap = null;
    static Map<String, String> datamap = null;

    public static void Method1(String url) {
//      String  url="http://oa.raycloud.com/login.php";
        Connection connection = Jsoup.connect(url);
        connection.timeout(1000 * 20);
        Connection.Response response = null;
        try {
            response = connection.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Map<String, String> map = response.cookies();
        String key;
        Iterator<String> keys = map.keySet().iterator();

        System.out.println("-----------------------coookie-------------------------");
        cookiemap = new HashMap<String, String>();
        while (keys.hasNext()) {
            key = keys.next();
            cookiemap.put(key, map.get(key));
            System.out.println(key + "=" + map.get(key));
        }
        Document document = null;
        try {
            document = connection.get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        datamap = new HashMap<String, String>();

        datamap.put("os_username","zuoyun");
        datamap.put("os_password","jik920717");
        datamap.put("os_destination","");


    }

    public static void Method2(String url) {

        Connection connection2 = Jsoup.connect(url);
        connection2.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        connection2.header("Accept-Encoding", "gzip, deflate");
        connection2.header("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
        connection2.header("Connection", "keep-alive");
        connection2.header("Referer", "http://doc.raycloud.com/login.action");
        connection2.header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0");
        connection2.cookies(cookiemap);
        connection2.data(datamap);
        try {
            connection2.post();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Connection.Response response2 = connection2.response();
        try {
            System.out.println(response2.parse());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        demo2_jsoup.Method1("http://doc.raycloud.com/login.action");
        demo2_jsoup.Method2("http://doc.raycloud.com/login.action");
    }
}
